package com.scy;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class Demo04 {

    public static void main(String[] args) throws IOException {
        DatagramSocket ds = new DatagramSocket(10086);
        //创建包对象
        DatagramPacket dp = new DatagramPacket(new byte[1024], 1024);
        System.out.println("等待接收数据...");
        ds.receive(dp); //阻塞
        //取数据
        byte[] data = dp.getData();
        int length = dp.getLength();
        String s = new String(data, 0, length);
        System.out.println("接收的数据为:"+s);
        //关连接
        ds.close();
    }
}
